home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / vla / dir_vla / d.inc < prev    next >
Text File  |  1993-09-15  |  10KB  |  446 lines

  1. ────────────────────────────────────────────────────────────────────────────
  2. PSPseg  dw  ?
  3. DTAseg  dw  ?
  4. ENVseg  dw  ?
  5.  
  6. FileSpec    db  "*.*",0
  7. CurDir      db  "?:\"
  8.  DirBuff    db  64 dup (0)
  9.  
  10. Msg_DirOf   db  "  Directory of ",0
  11. Msg_Spaces  db  "  ",0
  12. Msg_Bytes   db  " total bytes",13,10,0
  13. Msg_Files   db  " files",0
  14. Msg_File    db  " file ",0
  15. Msg_indent  db  "                ",0
  16. Msg_Free    db  " bytes free ",0
  17. Msg_Percent db  "%)"    ;,13,10,0
  18. Msg_CrLf    db  13,10,0
  19.  
  20. STRUC DTA
  21.     stuff   db  21 dup (?)
  22.     Attr    db  ?
  23.     Time    dw  ?
  24.     Date    dw  ?
  25.     Size    dd  ?
  26.     Fname   db  13 dup (0)
  27. ENDS
  28.  
  29. SizeSum     dd  0
  30. NumFiles    dd  0
  31.  
  32. Msg_Entry   db  "FileName Ext "
  33.  E_size     db  "9999999999 │ ",0
  34. ────────────────────────────────────────────────────────────────────────────
  35.     ────────────────────────────────────────────────────────────────────
  36.     ; Finds either the first or next entry. Updates the DTA
  37.     ;
  38.     ; IN: DS:DX points to ASCIIZ filename match
  39.     ;      AL = 4eh for Find First, 4fh for find next
  40.     ;      CX = attributes to search for
  41.     ;
  42.     ;OUT: CF = 0, Buffer is filled
  43.     ;     CF = 1, no more files, buffer unchanged
  44.     ────────────────────────────────────────────────────────────────────
  45. PROC FindFile NEAR
  46.     pusha
  47.  
  48.     int     21h
  49.     cmp     al,18
  50.     je   short @@NoMore
  51.     cmp     al,2
  52.     je   short @@NoMore
  53.     
  54.     clc
  55.     popa
  56.     ret
  57.  
  58. @@NoMore:
  59.     stc
  60.     popa
  61.     ret
  62. ENDP
  63.     ────────────────────────────────────────────────────────────────────
  64.     ; Finds either the first or next entry and puts it in a buffer
  65.     ;
  66.     ; IN:   FS = Ptr to the DTA segment
  67.     ────────────────────────────────────────────────────────────────────
  68. PROC PrintEntry NEAR
  69.     pusha
  70.     push    ds es
  71.     mov     ax,cs
  72.     mov     ds,ax
  73.     mov     es,ax
  74.  
  75.     mov     di,offset Msg_Entry
  76.     
  77.     push    di
  78.     mov     cx,23       ;clear out entry
  79.     mov     al," "
  80.     rep stosb
  81.     pop     di
  82.  
  83.     inc     [NumFiles]
  84.     mov     ah,2
  85.     xor     bx,bx
  86.     mov     cx,13
  87.     test    [fs:(DTA).Attr],00010000b
  88.     jz  short @@Ploop
  89.  
  90.  ;do a directory..
  91.  
  92.     dec     [NumFiles]
  93.     dec     cl
  94.     mov     al,"["
  95.     stosb
  96. @@DLoop:
  97.     mov     al,[fs:bx + (DTA).FName]
  98.     or      al,al
  99.     je short @@DDone
  100.     stosb
  101.     inc     bx
  102.     loop    @@Dloop
  103.  
  104. @@DDone:
  105.     mov     al,"]"
  106.     stosb
  107.     add     cx,10
  108.     mov     al," "
  109.     rep     stosb
  110.     jmp short @@END
  111.  
  112. @@PLoop:
  113.     mov     al,[fs:bx + (DTA).FName]
  114.     or      al,al
  115.     je  short @@Done
  116.     cmp     al,"."
  117.     je  short @@HitDot
  118.     stosb
  119.     inc     bx
  120.     loop    @@Ploop
  121.     jmp short @@Done
  122.  
  123. @@HitDot:
  124.     sub     cx,4
  125.     jle short @@Done
  126.     mov     al," "
  127.     rep stosb
  128.     mov     cx,4
  129.     inc     bx
  130.     jmp short @@PLoop
  131.  
  132. @@Done:
  133.     add     cx,2
  134.     mov     al," "
  135.     rep stosb
  136.     
  137. @@COnt:
  138.     mov     eax,[fs:(DTA).Size]
  139.     mov     cx,8
  140.     add     [SizeSum],eax
  141.     call    DEC_Print2Mem
  142.  
  143. @@End:
  144.     mov     si,offset Msg_Entry
  145.     call    PrintZ
  146.  
  147.     pop     es ds
  148.     popa
  149.     ret
  150. ENDP
  151.     ────────────────────────────────────────────────────────────────────
  152.     ; Prints out the message ' Directory of c:\directory\name '
  153.     ;
  154.     ; IN: DS = segment that all the data is in
  155.     ────────────────────────────────────────────────────────────────────
  156. PROC DisplayDirectory NEAR
  157.     pusha
  158.     mov     si,offset Msg_DirOf
  159.     call    PrintZ
  160.  
  161.     mov     ah,19h
  162.     int     21h
  163.     add     al,"A"
  164.     mov     [CurDir],al
  165.  
  166.     mov     ah,47h
  167.     xor     dl,dl
  168.     mov     si,offset DirBuff
  169.     int     21h
  170.     mov     si,offset CurDir
  171.     call    PrintZ
  172.     mov     si,offset Msg_CRLF
  173.     call    PrintZ
  174.  
  175.     popa
  176.     ret
  177. ENDP
  178.     ────────────────────────────────────────────────────────────────────
  179.     ; Displays the number of files, # of bytes used, bytes free, 
  180.     ; and % free on the disk
  181.     ────────────────────────────────────────────────────────────────────
  182. PROC PrintStats NEAR
  183.     pusha
  184.     mov     cx,10
  185.     mov     eax,[NumFiles]
  186.     call    Dec_Print
  187.     
  188.     mov     si,offset Msg_Files
  189.     cmp     [NumFiles],1
  190.     jne short @@OK
  191.     mov     si,offset Msg_File
  192. @@OK:
  193.     call    PrintZ
  194.  
  195.     mov     cx,10
  196.     mov     eax,[SizeSum]
  197.     call    Dec_Print
  198.  
  199.     mov     si,offset Msg_Bytes
  200.     call    PrintZ
  201.  
  202.     mov     si,offset Msg_Indent
  203.     call    PrintZ
  204.  
  205.     mov     ah,36h
  206.     xor     dl,dl
  207.     int     21h
  208.  
  209.     mul     bx
  210.     shl     edx,16
  211.     mov     dx,ax
  212.     movzx   eax,cx
  213.     mul     edx
  214.     mov     cx,10
  215.     call    DEC_Print
  216.  
  217.     mov     si,offset Msg_free
  218.     call    PrintZ
  219.  
  220.     mov     ah,2
  221.     mov     dl,"("
  222.     int     21h
  223.  
  224.     mov     ah,36h
  225.     xor     dl,dl
  226.     int     21h
  227.     movzx   eax,bx
  228.     imul    eax,100
  229.     movzx   ecx,dx
  230.  
  231.     push    eax ecx
  232.  
  233.     xor     edx,edx
  234.     div     ecx
  235.     push    eax
  236.     mov     cx,2
  237.     call    Dec_Print
  238.  
  239.     mov     ah,2
  240.     mov     dl,"."
  241.     int     21h
  242.  
  243.     pop     ebx ecx eax
  244.     imul    eax,1000
  245.     xor     edx,edx
  246.     div     ecx
  247.     imul    ebx,1000
  248.     sub     eax,ebx
  249.     mov     cx,3
  250.     call    Dec_Print
  251.  
  252.     mov     si,offset Msg_Percent
  253.     call    PrintZ
  254.     popa
  255.     ret
  256. ENDP
  257.     ────────────────────────────────────────────────────────────────────
  258.     ; Finds and displays all matching files.
  259.     ────────────────────────────────────────────────────────────────────
  260. PROC PrintEntries NEAR
  261.     pusha
  262.     push    fs
  263.     mov     fs,[cs:DTAseg]
  264.  
  265.     mov     dx,offset FileSpec
  266.     mov     cx,0110111b        ;search for all files
  267.     mov     ah,4eh              ;find first
  268.     call    FindFile
  269.     jc  short @@END
  270.  
  271.     call    PrintEntry
  272.  
  273.     mov     bp,2
  274. @@listLoop:
  275.     mov     dx,offset FileSpec
  276.     mov     cx,0110111b        ;search for all files
  277.     mov     ah,4fh              ;find next
  278.     call    FindFile
  279.     jc  short @@END
  280.  
  281.     call    PrintEntry
  282.     
  283.     dec     bp
  284.     jne short @@ListLoop
  285.  
  286.     mov     bp,3
  287.  
  288.     mov     si,offset Msg_Spaces
  289.     call    PrintZ
  290.     jmp short @@ListLoop
  291.  
  292. @@END:
  293.     mov     si,offset Msg_CRLF
  294.     call    PrintZ
  295.     pop     fs
  296.     popa
  297.     ret
  298. ENDP
  299. ────────────────────────────────────────────────────────────────────────────
  300.     ────────────────────────────────────────────────────────────────────
  301.     ;   Prints azero terminating string
  302.     ;
  303.     ; IN: ds:si = source
  304.     ;OUT:    cx = # of char written
  305.     ────────────────────────────────────────────────────────────────────
  306. PROC PrintZ
  307.     push    si dx ax
  308.     cld
  309.     xor     cx,cx
  310. @@TheLoop:
  311.     mov     dl,[si]
  312.     or      dl,dl
  313.     je  short @@Done
  314.     mov     ah,2
  315.     int     21h
  316.  
  317.     inc     cx
  318.     inc     si
  319.     jmp short @@TheLoop
  320.  
  321. @@Done:
  322.     pop     ax dx si
  323.     ret
  324. ENDP
  325.     ────────────────────────────────────────────────────────────────────
  326.     ; Print a number to memory
  327.     ; does not print leading zeros... prints spaces instead  
  328.     ;
  329.     ;IN: eax = number to print
  330.     ;     cx = number of digits to print (max 11)
  331.     ;  es:di = where to put the output
  332.     ────────────────────────────────────────────────────────────────────
  333. PROC DEC_Print2Mem NEAR
  334.     push    bp cx eax edx ebx si
  335.     cld
  336.     mov     bp,cx
  337.     
  338.     cld
  339.     xor     si,si
  340.     or      eax,eax
  341.     jns short @@NoPrintSign
  342.     inc     si              ;si not zero means we print a sign
  343.     dec     bp              ;count the sign
  344.     neg     eax
  345. @@NoPrintSign:
  346.  
  347.     mov     cx,11
  348.     mov     ebx,10
  349. @@DLNum:
  350.     xor     edx,edx
  351.     div     ebx
  352.     add     dl,'0'
  353.     push    dx      ;push the result
  354.     loop    @@DLNum
  355.  
  356.     mov     cx,11
  357.     mov     dh,0    ;flag if we hit non-zero yet
  358. @@DLNum2:
  359.     pop     ax
  360.     cmp     cx,bp
  361.     ja  short @@DontPrintThisYet
  362.     cmp     al,"0"
  363.     jne short @@NotZero
  364.     or      dh,dh
  365.     jne short    @@NotZero
  366.     cmp     cx,1
  367.     je  short    @@NotZero   ;print last zero if its leading
  368.     mov     al,' '
  369.     jmp short    @@PrintIt
  370. @@NotZero:
  371.     inc     dh
  372.     dec     si
  373.     js  short    @@PrintIt
  374.     mov     [BYTE es:di],"-"
  375.     inc     di
  376. @@Printit:
  377.     stosb
  378. @@DontPrintThisYet:
  379.     loop    @@DLNum2
  380.     
  381.     pop     si ebx edx eax cx bp
  382.     ret
  383. ENDP
  384.     ────────────────────────────────────────────────────────────────────
  385.     ; Print a number to the screen
  386.     ; does not print leading zeros... prints spaces instead
  387.     ;
  388.     ;IN: eax = number to print
  389.     ;     cx = number of digits to print (max 11)
  390.     ────────────────────────────────────────────────────────────────────
  391. PROC DEC_Print NEAR
  392.     push    bp cx eax edx ebx si
  393.     cld
  394.     mov     bp,cx
  395.     
  396.     xor     si,si
  397.     or      eax,eax
  398.     jns  short   @@PrintSign
  399.     inc     si              ;si not zero means we print a sign
  400.     dec     bp              ;count the sign
  401.     neg     eax
  402. @@PrintSign:
  403.  
  404.     mov     cx,11
  405.     mov     ebx,10
  406. @@DLNum:
  407.     xor     edx,edx
  408.     div     ebx
  409.     add     dl,'0'
  410.     push    dx      ;push the result
  411.     loop    @@DLNum
  412.  
  413.     mov     cx,11
  414.     mov     dh,0    ;flag if we hit non-zero yet
  415. @@DLNum2:
  416.     pop     ax
  417.     cmp     cx,bp
  418.     ja   short   @@DontPrintThisYet
  419.     cmp     al,"0"
  420.     jne  short   @@NotZero
  421.     or      dh,dh
  422.     jne  short   @@NotZero
  423.     cmp     cx,1
  424.     je   short   @@NotZero   ;print last zero if its leading
  425.     mov     al,' '
  426.     jmp  short   @@PrintIt
  427. @@NotZero:
  428.     inc     dh
  429.     dec     si
  430.     js   short   @@PrintIt
  431.     push    ax
  432.     mov     ah,2
  433.     mov     dl,"-"
  434.     int     21h
  435.     pop     ax
  436. @@Printit:
  437.     mov     ah,2
  438.     mov     dl,al
  439.     int     21h
  440. @@DontPrintThisYet:
  441.     loop    @@DLNum2
  442.  
  443.     pop     si ebx edx eax cx bp
  444.     ret
  445. ENDP
  446.